/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kjemprosj;

public class Titrering {

    private double konsSyre = 0.1;
    private double volumSyre = 50;
    private double konsBase = 0.1;
    private double volumBase = 51;
    private double totVol = 101;




    public Titrering(){};

    public boolean er7() {
        if(getPh(volumBase) == 7) {
            System.out.println("TIT");
            return true;
        }
        else {
            return false;
        }
    }

    public double getOriginalMolH(){
        return (konsSyre/1000) * volumSyre;
    }

    public double getMolOH(double mL){
        return (konsBase/1000) * mL;
    }

    public double getCurrentConsH(double mL){
        totVol = 0;
        totVol = volumSyre + mL;
        return (getOriginalMolH() - getMolOH(mL)) / (totVol/1000);
    }

    public double getCurrentConsOH(double mL){
        totVol = 0;
        totVol = volumSyre + mL;
        return ((getMolOH(mL) - getOriginalMolH()) / (totVol/1000));
    }


    public double getPh(double mL){
        volumBase = mL;
        if(getCurrentConsH(mL) < 0.0){
            return 14 - -java.lang.Math.log10(getCurrentConsOH(mL));
        }

       if(getCurrentConsH(mL) == 0.0){
           return 7;
       }
        return -java.lang.Math.log10(getCurrentConsH(mL));
    }

    public void setmL(double mL) {
        volumBase = mL;
    }

    @Override
    public String toString() {
        //Tilsatt base, mol OH-, kons av H+,pH

        String returnString = "";

        returnString += "Tilsatt base: " + volumBase + "\n";
        if(getCurrentConsH(volumBase)<0) {
            returnString += "Mol H+: 0 \n";
        } else {
            returnString += "Mol H+: " + getCurrentConsH(volumBase) + "\n";
        }
        if(getCurrentConsOH(volumBase)<0) {
            returnString += "Konsentrasjon OH-: 0 \n";
        } else {
            returnString += "Konsentrasjon OH-: " + getCurrentConsOH(volumBase) +"\n";
        }
        returnString += "PH: " + getPh(volumBase);

        return returnString;
    }
}
